package com.hyperchain.config;

import cn.dev33.satoken.stp.StpInterface;
import com.hyperchain.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Component
public class SaTokenPermissionConfig implements StpInterface {
    @Autowired
    private AuthService authService;
    /**
     * 当前账号拥有的权限集合
     * @param loginId 当前会话id  登录成功时set进去的-->StpUtil.login(user.getId());
     * @param loginType
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return new ArrayList<>(authService.userPermissionSet(Integer.parseInt((String) loginId)));
    }

    /**
     * 当前账号拥有的权限集合
     * @param loginId 当前会话id  登录成功时set进去的-->StpUtil.login(user.getId());
     * @param loginType
     * @return
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return new ArrayList<>(authService.userRoleSet(Integer.parseInt((String) loginId)));
    }
}
